<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>JSP - Hello World</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1><%= "Hello World!" %>
</h1>

<form action="Servlet" method="post">
    <%--@declare id="username"--%><%--@declare id="password"--%><label for="username">用户名</label>
    <input type="text" id="username" name="username" ><br>
<label for="password">密码</label>
    <input type="password" id="password" name="password"><br>
    <input type="submit" value="提交">
    <button content="submit()">ajax提交</button>
    <p id="msg"></p>
</form>

<script>
    function submit(){
       let username = $('#username').val();
       let password = $('#password').val();
       $.ajax({
           url:"longinAjax",
           type:"post",
           data:{'username':username,'password':password},
           success:function (data){
               console.log(data);
               $('#msg').text(data);
           },
       });
    }
</script>

<br/>
<a href="hello-servlet">Hello Servlet</a>
</body>
</html>